<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>

<body>
    <form class="layui-form layuimini-form" lay-filter="edit-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">zabbix_session串</label>
            <div class="layui-input-block">
                <input type="text" name="server_session" autocomplete="off" lay-verify="required" lay-reqtext="zabbix_session串不能为空"
                    placeholder="zbx_session=eyJzZXNzaW9uaWQiOiIzY2I5OGQ2MDhhN2Q3NWQ3YjgyOTEzMzU3NmQ5MmY5MCIsInNlcnZlckNoZWNrUmVzdWx0Ijp0cnVlLCJzZXJ2ZXJDaGVja1RpbWUiOjE2MTU1MzcyOTksInNpZ24iOiJLU1hwZ3hLTStkQUNIUWhzaDJ1Sm0zMllodm5NODkzaHZ1RWZ5bk1DNnJkZmwwTUFZbDBYNjFabVdkTWxsQTByU2NXVlNyY2tYdkZIWklcL2wwSkRcL1VncnRGUEFGaEFSOFVRQnJoRHplMmxjNjdzU1UyY3pUcXBLREkzZlp2XC9rNGVaU25Eb0hHc3FDeWh2QUtIbzFQQ1E9PSJ9" value="" class="layui-input">
                <tip>填写zabbix_session串。</tip>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">zabbix_session_js串</label>
            <div class="layui-input-block">
                <input type="text" name="server_session_js" autocomplete="off" lay-verify="required" lay-reqtext="zabbix_session_js串不能为空"
                    placeholder="zbx_session=eyJzZXNzaW9uaWQiOiIzY2I5OGQ2MDhhN2Q3NWQ3YjgyOTEzMzU3NmQ5MmY5MCIsInNlcnZlckNoZWNrUmVzdWx0Ijp0cnVlLCJzZXJ2ZXJDaGVja1RpbWUiOjE2MTU1MzcyNzksInNpZ24iOiJLU1hwZ3hLTStkQUNIUWhzaDJ1Sm0zMllodm5NODkzaHZ1RWZ5bk1DNnJkZmwwTUFZbDBYNjFabVdkTWxsQTByU2NXVlNyY2tYdkZIWklcL2wwSkRcL1VncnRGUEFGaEFSOFVRQnJoRHplMmxjNjdzU1UyY3pUcXBLREkzZlp2XC9rNHVxM0Y1dGtRXC92WmRnN0ExSmp6SENBPT0ifQ%3D%3D" value="" class="layui-input">
                <tip>填写zabbix_session_js串。</tip>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">server_ip</label>
            <div class="layui-input-block">
                <input type="text" name="server_ip" autocomplete="off" lay-verify="required" lay-reqtext="server_ip不能为空"
                    placeholder="http://172.25.62.10" value="" class="layui-input">
                <tip>填写server_ip。</tip>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button id="saveBtn" class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">保存</button>
                <button type="reset" class="layui-btn layui-btn-danger">重置</button>
                <input type="button" class="layui-btn layui-btn-primary goback" value="关闭"/>
            </div>
        </div>
    </form>
    <script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
    <script src="../../js/lay-config.js?v=2.0.0" charset="utf-8"></script>
    <script>
        (function initView() {
            var findOneUrl = "/zabbix/api/findOne";
            var saveOneUrl = "/zabbix/api/save";
            layui.use(['form','common','miniTab'], function () {
                var form = layui.form,
                    layer = layui.layer,
                    common = layui.common,
                    miniTab = layui.miniTab,
                    $ = layui.$;
                
                $.ajax({
                    url: findOneUrl,
                    data: {},
                    type: 'get',
                    dataType: 'json',
                    success: function (res) {
                        console.log(res);
                        if (res.code !== 0) {
                            layer.msg(res.msg, function () {
                            });
                        } else {
                            form.val('edit-form', res.data);
                        }
                    },
                    error: function (res) {
                        console.log(res);
                    }
                });


                //监听提交
                form.on('submit(saveBtn)', function (data) {
                    data = data.field;
                    console.log(data);
                    if (data.server_session.length > 500) {
                        layer.msg('系统类型名称太长!');
                        return false;
                    }
                    $("#saveBtn").attr('disabled','disabled');
                    $("#saveBtn").addClass("layui-btn-disabled");
                    $.ajax({
                        url: saveOneUrl,
                        data: data,
                        type: 'post',
                        dataType: 'json',
                        success: function (res) {
                            console.log(res);
                            if (res.code !== 0) {
                                layer.msg(res.msg, function () {
                                });
                            } else {
                                layer.msg(res.msg, function () {
                                });
                            }
                        },
                        error: function (res) {
                            console.log(res);
                            $("#saveBtn").removeAttr('disabled');
                            $("#saveBtn").removeClass("layui-btn-disabled");
                        }
                    });
                    return false;
                });

                $(".goback").click(function (e) {
                    miniTab.deleteCurrentByIframe();
                });

            });
        })();
    </script>
</body>

</html>